//
//  ViewController.m
//  12.UIView与核心动画区别?(掌握)
//
//  Created by xiaomage on 16/1/26.
//  Copyright © 2016年 小码哥. All rights reserved.
/**
  UIView与核心动画区别?(掌握)
 
   1.核心动画只作用在layer.
   2.核心动画看到的都是假像,它并没有去修改UIView的真实位置.
 
   什么时候使用核心动画?
   1.当不需要与用户进行交互,使用核心动画
   2.当要根据路径做动画时,使用核心动画
   3.当做转场动画时, 使用核心动画 (核心动画转场类型比较多)
 */

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    NSLog(@"%@",NSStringFromCGRect(self.redView.frame));
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
//    CABasicAnimation *anim = [CABasicAnimation animation];
//    anim.keyPath = @"position.y";
//    anim.toValue = @400;
//    anim.removedOnCompletion = NO;
//    anim.duration = 1;
//    anim.fillMode = kCAFillModeForwards;
//    anim.delegate = self;
//    [self.redView.layer addAnimation:anim forKey:nil];
    
    
    [UIView animateWithDuration:0.5 animations:^{
       
        self.redView.center = CGPointMake(50, 400);
        
    }completion:^(BOOL finished) {
         NSLog(@"%@",NSStringFromCGRect(self.redView.frame));
    }];
}

//动画开始时执行
-(void)animationDidStart:(CAAnimation *)anim {
    //NSLog(@"%s",__func__);
}

//动画完成时执行
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    //NSLog(@"%s",__func__);
  //  NSLog(@"finished==%@",NSStringFromCGRect(self.redView.frame));
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
